package com.qmx.qmxapp.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.qmx.qmxapp.R;
import com.qmx.qmxapp.base.BaseActivity;
import com.qmx.qmxapp.callback.DialogCallback;
import com.qmx.qmxapp.constant.AppConstant;
import com.qmx.qmxapp.constant.ComParamContact;
import com.qmx.qmxapp.utils.Validator;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author ChengXiangtong
 * @create 2018/11/6
 * @Describe 验证信息
 */
public class EmailVerifyActivity extends BaseActivity {
    @BindView(R.id.btn_verify_email)
    Button btn_verify_email;
    @BindView(R.id.ed_input_email)
    EditText ed_input_email;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_email_verify);
        ButterKnife.bind(this);


    }

    @OnClick(R.id.btn_verify_email)
    public void onClick(View view) {
        if (getEmail().isEmpty()) {
            return;
        }
        doVerify();
    }


    public String getEmail() {
        String email = ed_input_email.getText().toString();
        if (!TextUtils.isEmpty(email) && Validator.isEmail(email)) {
            return email;
        } else {
            showToast("请输入正确的邮箱地址");
            return "";
        }
    }


    private void doVerify() {
        OkGo.<String>post(AppConstant.Url + ComParamContact.validEmail.PATH)
                .params(ComParamContact.validEmail.EMAIL, getEmail())
                .execute(new DialogCallback<String>(this) {

                    @Override
                    public void onSuccess(Response<String> response) {
                        showToast(response.body());
//                            handleResponse(response);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        showToast("接口有问题");
//                            handleError(response);
                    }
                });
    }
}
